package com.gxsyh.nantie.login.provider.service.impl;

import com.gxsyh.nantie.login.provider.domain.TbUser;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.gxsyh.nantie.login.provider.mapper.TbUserMapper;
import com.gxsyh.nantie.login.provider.service.TbUserService;
import tk.mybatis.mapper.entity.Example;

/**
 * @email yom535@outlook.com
 * @author: 刘锋嘉(Liu Fengjia)
 * @date: 2020/1/2
 * @time: 11:19
 * @Description: 
 */
@Service
public class TbUserServiceImpl implements TbUserService{

    @Resource
    private TbUserMapper tbUserMapper;

    @Override
    public TbUser selectOneTbUserByUsername(String username) {
        Example example=new Example(TbUser.class);
        //只查找启用了的账户
        example.createCriteria().andEqualTo("username",username).andEqualTo("userStatus",1);
        return tbUserMapper.selectOneByExample(example);
    }

    @Override
    public TbUser selectOneTbUserById(Long id) {
        Example example=new Example(TbUser.class);
        example.createCriteria().andEqualTo("id",id);
        return tbUserMapper.selectOneByExample(example);
    }

    @Override
    public int updateOneTbUserByRefresh_token(String username, String refresh_token) {
        Example example=new Example(TbUser.class);

        example.createCriteria().andEqualTo("username",username);

        TbUser tbUser=new TbUser();
        tbUser.setRefresh_token(refresh_token);
        return tbUserMapper.updateByExampleSelective(tbUser,example);
    }
}
